import { CellRenderer } from "../../../../fl/controls/listClasses/CellRenderer";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { GLabel } from "../../../../com/mui/controls/GLabel";
import { Language } from "../../../../extend/language/Language";
import { WaitingPlayerData } from "../copy/group/WaitingPlayerData";
import { CareerConfig } from "../../resource/CareerConfig";
import { EntityUtil } from "../../scene/layer/utils/EntityUtil";
import { Cache } from "../../cache/Cache";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { GroupUtil } from "../group/GroupUtil";
import { AvatarInfo } from "../../resource/info/AvatarInfo";
import { AvatarType } from "../../resource/info/AvatarType";
import { ImageInfo } from "../../../../com/gengine/resource/info/ImageInfo";
import { SPublicMiniPlayer } from "../../../../Message/Public/SPublicMiniPlayer";
import { ThingUtil } from "../../scene/layer/utils/ThingUtil";
import { IEntity } from "../../scene/player/IEntity";
import { MsgManager } from "../../manager/MsgManager";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { GButton } from "../../../../com/mui/controls/GButton";
//class NearbyListCellRenderer
    
    export  class NearbyListCellRenderer extends CellRenderer
    {
        constructor()
        {
            super();
            this.mouseChildren = true;
            this.initStyle();
            this.createChildren();
            return;
        }

        /* internal  */initStyle(): void
        {
            this.setStyle("upSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("downSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("overSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("selectedDownSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("selectedOverSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("selectedUpSkin", new Object /* flash.display.Bitmap */());
            return;
        }

        /* internal  */createChildren(): void
        {
            ObjCreate.createBg(0, 36, 328, 2, this, ImagesConst.SplitLine);
            this._headImg = new Object /* flash.display.Bitmap */();
            this._headImg.x = 5;
            this._headImg.y = 7;
            this.addChild(this._headImg);
            this.nameLabel = new GLabel();
            addChild(this.nameLabel);
            this.nameLabel.setSize(98, 22);
            this.nameLabel.x = 30;
            this.nameLabel.y = 9;
            this.nameLabel.mouseEnabled = false;
            this.levelLabel = new GLabel();
            addChild(this.levelLabel);
            this.levelLabel.setSize(30, 22);
            this.levelLabel.x = 120;
            this.levelLabel.y = 9;
            this.levelLabel.mouseEnabled = false;
            this.careerLabel = new GLabel();
            addChild(this.careerLabel);
            this.careerLabel.setSize(76, 22);
            this.careerLabel.x = 157;
            this.careerLabel.y = 9;
            this.careerLabel.mouseEnabled = false;
            this.processLabel = new GLabel();
            addChild(this.processLabel);
            this.processLabel.setSize(76, 22);
            this.processLabel.x = 200;
            this.processLabel.y = 9;
            this.processLabel.mouseEnabled = false;
            this._inviteBtn = ObjCreate.createGButton(Language.getString(62057), 250, 6, 70, 22, this);
            this._inviteBtn.drawNow();
            this._inviteBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onInviteBtnClick);
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            var loc2=null;
            var loc3=null;
            var loc4=null;
            super.data = arg1;
            var loc1=arg1 as WaitingPlayerData;
            if (loc1) 
            {
                this._isCross = loc1.isCross;
                loc3 = loc1.player;
                if (CareerConfig.instance.getInfoByCode(loc3.career)) 
                {
                    loc2 = CareerConfig.instance.getInfoByCode(loc3.career).name;
                    if (EntityUtil.toString(loc3.entityId) != EntityUtil.toString(Cache.instance.role.entityInfo.entityId)) 
                    {
                        loc4 = "#B1EFFE";
                    }
                    else 
                    {
                        loc4 = "#FFFF00";
                    }
                    this.nameLabel.htmlText = HTMLUtil.addColor(loc3.name, loc4);
                    this.levelLabel.htmlText = HTMLUtil.addColor(loc3.level + "", loc4);
                    this.careerLabel.htmlText = HTMLUtil.addColor(loc2, loc4);
                    this.processLabel.htmlText = HTMLUtil.addColor(GroupUtil.getProcessStr(loc1.waitingPlayer, loc1.copyId), "#FFFF00");
                    AvatarInfo.getAvatar(loc3.camp, loc3.sex, AvatarType.SMALL, this.onAvatarLoaded, loc3.avatarId);
                }
            }
            return;
        }

        /* internal  */onAvatarLoaded(arg1: ImageInfo): void
        {
            this._headImg.bitmapData = arg1.bitmapData;
            this._headImg.width = 22;
            this._headImg.height = 22;
            return;
        }

        /* internal  */onInviteBtnClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc4=null;
            var loc1=data["player"] as SPublicMiniPlayer;
            var loc2=false;
            var loc3=ThingUtil.entityUtil.getAllUserList();
            var loc5=0;
            while (loc5 < loc3.length) 
            {
                loc4 = (loc3[loc5] as IEntity).entityInfo.entityInfo;
                if (EntityUtil.toString(loc4.entityId) == EntityUtil.toString(loc1.entityId)) 
                {
                    if (!this._isCross && loc4.groupId && loc4.groupId.length > 0 || this._isCross && loc4.crossGroupId && loc4.crossGroupId.length > 0) 
                    {
                        loc2 = true;
                    }
                    break;
                }
                ++loc5;
            }
            if (loc2) 
            {
                if (loc2) 
                {
                    MsgManager.showRollTipsMsg(Language.getString(62058));
                }
                Dispatcher.dispatchEvent(new DataEvent(EventName.CopyGroupRefreshNearby));
            }
            else if (this._isCross) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.CrossGroup_DoInvite, loc1.entityId));
            }
            else 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.Group_DoInvite, loc1.entityId));
            }
            return;
        }

        public /* override */ set label(arg1: string)
        {
            return;
        }

        /* internal */ /* var */_isCross: Boolean;

        /* internal */ /* var */_headImg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */nameLabel: GLabel;

        /* internal */ /* var */levelLabel: GLabel;

        /* internal */ /* var */careerLabel: GLabel;

        /* internal */ /* var */processLabel: GLabel;

        /* internal */ /* var */_inviteBtn: GButton;
    }
